#!/usr/bin/env bash
# Copyright (c) 2021 Presto Labs Pte. Ltd.
# Author: fengyang

set -e

# Source miniconda
if [ ${CONDA_PREFIX} ]; then
    echo "run conda deactivate"
    exit 1;
fi
source $HOME/miniconda3/etc/profile.d/conda.sh
conda update -y -n base -c defaults conda

# Create env
CONDA_TARGET_ENV=${CONDA_TARGET_ENV:-kline_plot_env}
(conda env remove -y -n $CONDA_TARGET_ENV || true)
conda create -y -n $CONDA_TARGET_ENV
conda activate $CONDA_TARGET_ENV

# Install nodejs
conda install -y -c conda-forge \
    nodejs \
    python \
    ;

# Upgrade nodejs to latest
conda update nodejs -y


# install dependened nodejs package
cd front
npm install

# Intall flask
pip install --upgrade pip
pip install \
    flask \
    ;

# Cleanup env
if [ "${CONDA_TARGET_ENV}" != "${CONDA_DEFAULT_ENV}" ]; then
    echo "inconsistent conda env"
    exit 1
fi
conda deactivate
